package stream;

import javafx.util.Pair;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class streamMain {

    public static void main(String[] args) {
        List<Dish> menu = Arrays.asList(
                new Dish("pork", false, 800, Dish.Type.MEAT),
                new Dish("beef", false, 700, Dish.Type.MEAT),
                new Dish("chicken", false, 400, Dish.Type.MEAT),
                new Dish("french fries", true, 530, Dish.Type.OTHER),
                new Dish("rice", true, 350, Dish.Type.OTHER),
                new Dish("season fruit", true, 120, Dish.Type.OTHER),
                new Dish("pizza", true, 550, Dish.Type.OTHER),
                new Dish("prawns", false, 300, Dish.Type.FISH),
                new Dish("salmon", false, 450, Dish.Type.FISH) );

        List<Integer> list1 = Arrays.asList(1, 2, 3);
        List<Integer> list2 = Arrays.asList(3, 4);
        List<Pair<Integer, Integer>> result = new ArrayList<>();
        list1.forEach(v1 -> {
            list2.forEach(v2 -> {
                result.add(new Pair<>(v1, v2));
            });
        });
        System.out.println(result);

        List<Pair<Integer, Integer>> collect = list1.stream()
                .flatMap(v1 -> list2.stream().map(v2 -> new Pair<>(v1, v2)))
                .filter(pair -> (pair.getKey() + pair.getValue()) % 3 == 0 )
                .collect(Collectors.toList());
        System.out.println(collect);

        collect = list1.stream()
                .flatMap(v1 -> list2.stream()
                        .filter(v2 -> (v1 + v2) % 3 == 0)
                        .map(v2 -> new Pair<>(v1, v2)))
                .collect(Collectors.toList());
        System.out.println(collect);

    }
}
